package edu.hunan.cxb18.dao.Impl;

import edu.hunan.cxb18.dao.AccountDao;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Repository;

/**
 * @author chenheng
 * @create 2020-03-26 9:24
 */
@Repository
public class AccountDaoImpl implements AccountDao {
    @Autowired
    private JdbcTemplate jdbcTemplate;
    @Override
    public double queryBalance(String username) {
        return jdbcTemplate.queryForObject("select balance from t_account where username=? ",new Object[]{username},Double.class);
    }

    @Override
    public void updateBalance(String username, double amount) {
        jdbcTemplate.update("update t_account set balance=balance-? where username=?",amount,username);
    }
}
